import 'package:flutter/material.dart';
import 'package:flutter_hsh/fam/assets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class LoadingDialog extends StatefulWidget {
  const LoadingDialog({Key? key, required this.title}) : super(key: key);
  final String title;

  static void show(String title) async {
    Get.dialog(LoadingDialog(title: title), barrierDismissible: false);
  }

  @override
  State<LoadingDialog> createState() => _LoadingDialogState();
}

class _LoadingDialogState extends State<LoadingDialog> with SingleTickerProviderStateMixin {
  late AnimationController controller;
  @override
  void initState() {
    super.initState();
    controller = AnimationController(duration: const Duration(seconds: 2), vsync: this);
    controller.repeat();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
        canPop: false,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RotationTransition(
              alignment: Alignment.center,
              turns: controller,
              child: Image.asset(Assets.loading, width: 88.w),
            ).paddingOnly(bottom: 16),
            Text(widget.title, style: TextStyle(fontSize: 14.w, color: Colors.white, fontWeight: FontWeight.w600)),
          ],
        ));
  }
}
